# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        a=ListNode((l1.val+l2.val)%10)
        b=a
        pre = (l1.val+l2.val)//10
        while l1.next or l2.next:
            v1 = 0
            v2 = 0
            if l1.next:
                l1=l1.next
                v1 = l1.val
            if l2.next:
                l2 = l2.next
                v2 = l2.val
            
            b.next=ListNode(v1+v2+pre)
            b=b.next
            pre = b.val//10
            b.val=b.val%10
        if pre:
            b.next = ListNode(pre)
        return a